/**
 * Command line entry [命令行入口]
 */
const program = require('commander')
const _ = require('lodash')
const path = require('path')
const pkg = require('./package.json')
const { init, api, project, socket, protobuf, apiConfig } = require('./build/main')

const basename = path.basename(process.env._ || process.title.replace(/^(\S+)(\s\-\s)(\S+)$/, '$3'))

program
  .version(pkg.version)

program
  .name(basename === 'node' ? 'gmc' : basename)
  .usage('[command] [options]')

program
  .command('init')
  .description(`初始化配置 ...`)
  .action( init )

program
  .command('test')
  .description(`调试接口 ...`)
  .action( api )

program
  .command('project')
  .description(`配置项目 ...`)
  .action( project )

program
  .command('socket')
  .description(`配置 Socket连接 ...`)
  .action( socket )

program
  .command('protobuf')
  .description(`更新 Protobuf ...`)
  .action( protobuf )

program
  .command('interface')
  .description(`API配置接口 ...`)
  .action( apiConfig )

// Parse and fallback to help if no args
if (_.isEmpty(program.parse(process.argv).args) && process.argv.length === 2) {
  program.help()
}